attribute float glhfVertexY;
attribute float glhfVertexMorphY;
attribute vec4  glhfVertexBorderMask;
attribute float glhfVertexLevel;
attribute vec2  glhfVertexXZ;

uniform float glhfChunkLod;
uniform vec4  glhfNeighborLods;
uniform vec2  glhfChunkOriginXZ;

uniform vec2 glhfTexCoordScale;
uniform vec2 glhfTexCoordOffset;

vec3 glhfVertex()
{
  float vertexLod = (1.0-(glhfVertexBorderMask.x+
                          glhfVertexBorderMask.y+
                          glhfVertexBorderMask.z+
                          glhfVertexBorderMask.w))*glhfChunkLod + dot(glhfVertexBorderMask,glhfNeighborLods);

  vec3 vertex;

  vertex.y = (glhfVertexLevel==floor(vertexLod)) ? mix(glhfVertexY,glhfVertexMorphY,vertexLod-floor(vertexLod)) : glhfVertexY;

  vertex.xz  = glhfChunkOriginXZ + glhfVertexXZ;

  return vertex;
}

vec2 glhfTexCoord(vec3 vertex)
{
  return vertex.xz*glhfTexCoordScale + glhfTexCoordOffset;
}
